
log using "$plots/Event_study_closures_log.smcl", replace
display "`c(current_time)' `c(current_date)'"

local window_begin = 15
local window_end = 43

// Main specification: Chaisemartin on county level and clusters on the state level
foreach a of numlist 1 2 3 4{
use "$altered_data/event_study_vaccination.dta", clear
keep if date >= td(13jun2021) //two weeks before first school closes
drop if treated == 1 //counties that opened again drop out of control group
gen vac_rate_lag14 = cum_cases_14_lag / pop_total

keep if age == `a'


	if `a' == 1 {
		local header "Age: 5 - 14"
	}
	if `a' == 2 {
		local header "Age: 15 - 34"
	} 
	if `a' == 3 {
		local header "Age: 35 - 59"
	} 
	if `a' == 4 {
		local header "Age: 60+"
	}

	
did_multiplegt cases_melde RS date treated_c, robust_dynamic controls(cases_cum14 vac_rate_lag14 mob*)  placebo(`window_begin') dynamic(`window_end') breps(100) cluster(idbundesland) weight(pop_total) save_results("$altered_data/did_multiplegt_`a'_closures.dta")

use "$altered_data/did_multiplegt_`a'_closures.dta", clear
scatter treatment_effect treatment_effect_lower_95CI treatment_effect_upper_95CI time_to_treatment, ///
c(l l l) cmissing(n n n) msym(i i i) lcolor(gs4 gs10 gs10) lpattern(solid solid solid) lwidth(thick medthick medthick) ///
yline(0, lcolor(black)) xline(0, lcolor(black)) ///
legend(order(1  2) label(1 "Point estimates") label(2 "95% CI") cols(2)) ///
subtitle("", size(vsmall) j(left) pos(11)) ///
ylabel(-30(10)30,nogrid angle(horizontal) labsize(small)) graphregion(color(white)) ///
xtitle("Days relative to start of summer break") xlab(-`window_begin'(5)`window_end')  name("did_gt_`a'", replace)  title("`header'", color(black))  
}

grc1leg did_gt_1 did_gt_2 did_gt_3 did_gt_4, graphregion(color(white)) ycommon
graph export "${plots}chaise_main_closures.png", replace width(3000)

display "`c(current_time)' `c(current_date)'"
log close
translate Event_study_closures_log.smcl Event_study_closures_log.pdf
exit

